package com.beta.util;

import android.annotation.SuppressLint;

public class HexUtil
{
  @SuppressLint("DefaultLocale")
public static String byte2HexString(byte paramByte)
  {
    String str = String.valueOf(Integer.toHexString(paramByte & 0xFF)).toUpperCase();
    if (str.length() == 1)
      str = "0".concat(str);
    return str;
  }

  public static byte[] decode(String hexStr) {  
      if (hexStr.length() < 1)  
          return null;  
      byte[] result = new byte[hexStr.length()/2];  
      for (int i = 0;i< hexStr.length()/2; i++) {  
          int high = Integer.parseInt(hexStr.substring(i*2, i*2+1 ), 16);  
          int low = Integer.parseInt(hexStr.substring(i*2+1, i*2+2), 16);  
          result[i] = (byte) (high * 16 + low);  
      }  
      return result;  
  }  
  
  public static String encode(byte[] paramArrayOfByte)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    int i = paramArrayOfByte.length;
    for (int j = 0; ; j++)
    {
      if (j >= i)
        return localStringBuffer.toString();
      localStringBuffer.append(byte2HexString(paramArrayOfByte[j]));
    }
  }

}
